﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using System.Windows.Forms;

namespace 图书管理系统
{
    class UserDao
    {
        public int updateBorrow_num(String ReaderID)
        {
            int num = 0;
            SqlConnection conn = new SqlConnection();
            String sql = "update Readerinfo set Borrow_num=Borrow_num+1 where ReaderID='" + ReaderID + "'";
            SqlCommand cmd = Dao.SqlConnect(sql, conn);
            try
            {
                conn.Open();
                num = cmd.ExecuteNonQuery();

            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }  
            return num;
        }
        public Boolean judge(String ReaderID,String Identy)
        {
            SqlConnection conn = new SqlConnection();
            String sql = "select Borrow_num from Readerinfo where ReaderID='"+ReaderID+"'";
            SqlCommand cmd = Dao.SqlConnect(sql, conn);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            String num = null;
            while (reader.Read())
              {
                   num = reader[0].ToString();
              }
            int k = int.Parse(num);
            if(Penatynum(ReaderID,Identy)-k>0)
            {
                conn.Close();
                return true;
            }
            else
            {
                conn.Close();
                return false;

            }
           
        }
        public int Penatynum(String ReaderID,String Identy)
        {
            SqlConnection conn = new SqlConnection();
            String sql1 = "select Borrow_num from Borrowingrules_Table where Identy='" + Identy + "'";
            SqlCommand cmd1 = Dao.SqlConnect(sql1, conn);
            conn.Open();
            SqlDataReader reader1 = cmd1.ExecuteReader();
            String num1 = null;
            while (reader1.Read())
            {
                num1 = reader1[0].ToString();
            }
            int j = int.Parse(num1);
            conn.Close();
            return j;
        }
    }
}
